/*
 * Receptor de Servicio
 */
package edu.umss.arqui10.modelo;

import java.io.Serializable;
import java.util.ArrayList;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Column;
import javax.persistence.Table;

import java.util.Date;
import java.util.List;
import javax.persistence.Temporal;

/**
 *
 * @author Rho1and0
 */
@Entity
@Table(name="service_receiver")
public class ServiceReceiver implements Serializable {

    @Column(name="name")
    private String name;

    @Column(name="Registry_Date")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date RegistryDate;

    @Column(name="holders")
    private List<Pair<Holder, Double>> holders; 
   
   
    private double total;

    @ManyToOne
    private History history;

    @Id
    private Long id;
    @ManyToMany(mappedBy = "receivers")
    private List<Responsible> responsibles;

    public ServiceReceiver() {
    }

    public ServiceReceiver(String name) {
        this.name = name;
        history = new History();
        holders = new ArrayList<Pair<Holder,Double>>();
    }

    public void addHolder(Holder t, double p) {
        
    }

    public void delHolder(Holder holder) {

    }

    public void percentageCalculate() {

    }

    public String getName() {
        return name;
    }

    

    public double getPercentage(Holder t) {
        return 0.0;
    }

    public void setPercentage(Holder t, double p) {
    }

    public void createHistory() {
        this.history = new History();
    }

    public History getHistory() {
        return this.history;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void openRegistry(String antecedent) {
        this.history.openRegistry(antecedent);
    }

    public ArrayList<Pair<Holder, Double>> getHolders() {
        return (ArrayList<Pair<Holder, Double>>)holders;
    }

    public void assignService(Service serv) {
        this.history.assignService(serv);
    }

    public String getService(String nameServ) {
        String res = "";
        Registry reg = this.history.getOpenRegistry();
        
        if(reg != null) {
            Service serv = reg.getService(nameServ);
            if(serv != null)
                res = serv.toString();
        }

        return res;
    }
}
